using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWPREKOPF
    {
        public DataRow Convert2WPREKOPF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWPREKOPF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WRKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WRKLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["WRKREART"] = " ".PadRight(1 ); 
         dwReturn["WRKRENR"] = " ".PadRight(15 ); 
         dwReturn["WRKAENZL"] = " ".PadRight(0 ); 
         dwReturn["WRKAENB"] = " ".PadRight(8 ); 
         dwReturn["WRKAEND"] = " ".PadRight(0 ); 
         dwReturn["WRKNEUB"] = " ".PadRight(8 ); 
         dwReturn["WRKNEUD"] = " ".PadRight(0 ); 
         dwReturn["WRKREDAT"] = " ".PadRight(0 ); 
         dwReturn["WRKSTA"] = " ".PadRight(1 ); 
         dwReturn["WRKKONDSL"] = " ".PadRight(4 ); 
         dwReturn["WRKWAEHRSL"] = " ".PadRight(3 ); 
         dwReturn["WRKLIEFNRB"] = " ".PadRight(8 ); 
         dwReturn["WRKUMFAK"] = " ".PadRight(18 ); 
         dwReturn["WRKSTDSKT"] = " ".PadRight(1 ); 
         dwReturn["WRKSKTTAGE01"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTP01"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTTAGE02"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTP02"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTTAGE03"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTP03"] = " ".PadRight(0 ); 
         dwReturn["WRKVALUTA"] = " ".PadRight(0 ); 
         dwReturn["WRKWERTDAT"] = " ".PadRight(0 ); 
         dwReturn["WRKNETTO"] = " ".PadRight(0 ); 
         dwReturn["WRKVERPACK"] = " ".PadRight(0 ); 
         dwReturn["WRKFRACHT"] = " ".PadRight(0 ); 
         dwReturn["WRKVERSICH"] = " ".PadRight(0 ); 
         dwReturn["WRKZOLL"] = " ".PadRight(0 ); 
         dwReturn["WRKUSTPRZ"] = " ".PadRight(0 ); 
         dwReturn["WRKUST"] = " ".PadRight(0 ); 
         dwReturn["WRKREWERT"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTBETR"] = " ".PadRight(0 ); 
         dwReturn["WRKSKTWERT"] = " ".PadRight(0 ); 
         dwReturn["WRKFIBUDAT"] = " ".PadRight(0 ); 
         dwReturn["WRKFIBUBELEG"] = " ".PadRight(0 ); 
         dwReturn["WRKABRECHKZ"] = " ".PadRight(1 ); 
         dwReturn["WRKFILLER"] = " ".PadRight(44 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWPREKOPF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWPREKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWPREKOPF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWPREKOPF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWPREKOPF(dwLocal, ITXDBVERSION);
            }
            UpdateWPREKOPF(dwLocal);
        }
        public void InsertWPREKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WPREKOPF(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWPREKOPF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WPREKOPF WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WPREKOPF  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WPREKOPF";
            Return = Result;
            return Return;
        }
        public void DeleteWPREKOPF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WPREKOPF   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWPREKOPF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WPREKOPF SET "
                    +"WRKMANDANT= :WRKMANDANT,"
                    +"WRKLIEFNR= :WRKLIEFNR,"
                    +"WRKREART= :WRKREART,"
                    +"WRKRENR= :WRKRENR,"
                    +"WRKAENZL= :WRKAENZL,"
                    +"WRKAENB= :WRKAENB,"
                    +"WRKAEND= :WRKAEND,"
                    +"WRKNEUB= :WRKNEUB,"
                    +"WRKNEUD= :WRKNEUD,"
                    +"WRKREDAT= :WRKREDAT,"
                    +"WRKSTA= :WRKSTA,"
                    +"WRKKONDSL= :WRKKONDSL,"
                    +"WRKWAEHRSL= :WRKWAEHRSL,"
                    +"WRKLIEFNRB= :WRKLIEFNRB,"
                    +"WRKUMFAK= :WRKUMFAK,"
                    +"WRKSTDSKT= :WRKSTDSKT,"
                    +"WRKSKTTAGE01= :WRKSKTTAGE01,"
                    +"WRKSKTP01= :WRKSKTP01,"
                    +"WRKSKTTAGE02= :WRKSKTTAGE02,"
                    +"WRKSKTP02= :WRKSKTP02,"
                    +"WRKSKTTAGE03= :WRKSKTTAGE03,"
                    +"WRKSKTP03= :WRKSKTP03,"
                    +"WRKVALUTA= :WRKVALUTA,"
                    +"WRKWERTDAT= :WRKWERTDAT,"
                    +"WRKNETTO= :WRKNETTO,"
                    +"WRKVERPACK= :WRKVERPACK,"
                    +"WRKFRACHT= :WRKFRACHT,"
                    +"WRKVERSICH= :WRKVERSICH,"
                    +"WRKZOLL= :WRKZOLL,"
                    +"WRKUSTPRZ= :WRKUSTPRZ,"
                    +"WRKUST= :WRKUST,"
                    +"WRKREWERT= :WRKREWERT,"
                    +"WRKSKTBETR= :WRKSKTBETR,"
                    +"WRKSKTWERT= :WRKSKTWERT,"
                    +"WRKFIBUDAT= :WRKFIBUDAT,"
                    +"WRKFIBUBELEG= :WRKFIBUBELEG,"
                    +"WRKABRECHKZ= :WRKABRECHKZ,"
                    +"WRKFILLER= :WRKFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WRKMANDANT", OracleType.NVarChar).Value = dwData["WRKMANDANT"].ToString(); 
          or1.Parameters.Add("WRKLIEFNR", OracleType.NVarChar).Value = dwData["WRKLIEFNR"].ToString(); 
          or1.Parameters.Add("WRKREART", OracleType.NVarChar).Value = dwData["WRKREART"].ToString(); 
          or1.Parameters.Add("WRKRENR", OracleType.NVarChar).Value = dwData["WRKRENR"].ToString(); 
          or1.Parameters.Add("WRKAENZL", OracleType.NVarChar).Value = dwData["WRKAENZL"].ToString(); 
          or1.Parameters.Add("WRKAENB", OracleType.NVarChar).Value = dwData["WRKAENB"].ToString(); 
          or1.Parameters.Add("WRKAEND", OracleType.NVarChar).Value = dwData["WRKAEND"].ToString(); 
          or1.Parameters.Add("WRKNEUB", OracleType.NVarChar).Value = dwData["WRKNEUB"].ToString(); 
          or1.Parameters.Add("WRKNEUD", OracleType.NVarChar).Value = dwData["WRKNEUD"].ToString(); 
          or1.Parameters.Add("WRKREDAT", OracleType.NVarChar).Value = dwData["WRKREDAT"].ToString(); 
          or1.Parameters.Add("WRKSTA", OracleType.NVarChar).Value = dwData["WRKSTA"].ToString(); 
          or1.Parameters.Add("WRKKONDSL", OracleType.NVarChar).Value = dwData["WRKKONDSL"].ToString(); 
          or1.Parameters.Add("WRKWAEHRSL", OracleType.NVarChar).Value = dwData["WRKWAEHRSL"].ToString(); 
          or1.Parameters.Add("WRKLIEFNRB", OracleType.NVarChar).Value = dwData["WRKLIEFNRB"].ToString(); 
          or1.Parameters.Add("WRKUMFAK", OracleType.NVarChar).Value = dwData["WRKUMFAK"].ToString(); 
          or1.Parameters.Add("WRKSTDSKT", OracleType.NVarChar).Value = dwData["WRKSTDSKT"].ToString(); 
          or1.Parameters.Add("WRKSKTTAGE01", OracleType.NVarChar).Value = dwData["WRKSKTTAGE01"].ToString(); 
          or1.Parameters.Add("WRKSKTP01", OracleType.NVarChar).Value = dwData["WRKSKTP01"].ToString(); 
          or1.Parameters.Add("WRKSKTTAGE02", OracleType.NVarChar).Value = dwData["WRKSKTTAGE02"].ToString(); 
          or1.Parameters.Add("WRKSKTP02", OracleType.NVarChar).Value = dwData["WRKSKTP02"].ToString(); 
          or1.Parameters.Add("WRKSKTTAGE03", OracleType.NVarChar).Value = dwData["WRKSKTTAGE03"].ToString(); 
          or1.Parameters.Add("WRKSKTP03", OracleType.NVarChar).Value = dwData["WRKSKTP03"].ToString(); 
          or1.Parameters.Add("WRKVALUTA", OracleType.NVarChar).Value = dwData["WRKVALUTA"].ToString(); 
          or1.Parameters.Add("WRKWERTDAT", OracleType.NVarChar).Value = dwData["WRKWERTDAT"].ToString(); 
          or1.Parameters.Add("WRKNETTO", OracleType.NVarChar).Value = dwData["WRKNETTO"].ToString(); 
          or1.Parameters.Add("WRKVERPACK", OracleType.NVarChar).Value = dwData["WRKVERPACK"].ToString(); 
          or1.Parameters.Add("WRKFRACHT", OracleType.NVarChar).Value = dwData["WRKFRACHT"].ToString(); 
          or1.Parameters.Add("WRKVERSICH", OracleType.NVarChar).Value = dwData["WRKVERSICH"].ToString(); 
          or1.Parameters.Add("WRKZOLL", OracleType.NVarChar).Value = dwData["WRKZOLL"].ToString(); 
          or1.Parameters.Add("WRKUSTPRZ", OracleType.NVarChar).Value = dwData["WRKUSTPRZ"].ToString(); 
          or1.Parameters.Add("WRKUST", OracleType.NVarChar).Value = dwData["WRKUST"].ToString(); 
          or1.Parameters.Add("WRKREWERT", OracleType.NVarChar).Value = dwData["WRKREWERT"].ToString(); 
          or1.Parameters.Add("WRKSKTBETR", OracleType.NVarChar).Value = dwData["WRKSKTBETR"].ToString(); 
          or1.Parameters.Add("WRKSKTWERT", OracleType.NVarChar).Value = dwData["WRKSKTWERT"].ToString(); 
          or1.Parameters.Add("WRKFIBUDAT", OracleType.NVarChar).Value = dwData["WRKFIBUDAT"].ToString(); 
          or1.Parameters.Add("WRKFIBUBELEG", OracleType.NVarChar).Value = dwData["WRKFIBUBELEG"].ToString(); 
          or1.Parameters.Add("WRKABRECHKZ", OracleType.NVarChar).Value = dwData["WRKABRECHKZ"].ToString(); 
          or1.Parameters.Add("WRKFILLER", OracleType.NVarChar).Value = dwData["WRKFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
